package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.QuotationProxy;
	import vn.demand.dragon.view.QuotationNewFormMediator;
	import vn.demand.dragon.view.components.QuotationForm;
	
	public class NewCompanyCommand extends SimpleCommand
	{
		public static var countNewCompany:int = 0;
		
		override public function execute( note:INotification ) :void    
		{
			var quotationVO:Object = {quote_code: 'New quotation ' + (++countNewCompany), quote_status: 9};
			if (facade.hasMediator(QuotationNewFormMediator.makeId(quotationVO))) {
				TabManager.openTab(QuotationNewFormMediator, QuotationNewFormMediator.makeId(quotationVO));
				return;
			}
			var ui:QuotationForm = TabManager.openTab(QuotationForm, QuotationNewFormMediator.makeId(quotationVO)) as QuotationForm;
            var formId:String = QuotationNewFormMediator.makeId(quotationVO)
            facade.registerProxy(new QuotationProxy(formId, quotationVO));
            facade.registerMediator(new QuotationNewFormMediator(quotationVO, formId, ui));
        }

	}
}